/**
 * Game
 * When intantiated, will run the game (using run() method).
 * @author Alan Marvel
 */
public class Game
{
	private final int PARTY_SIZE = 4, START_LOCATION = 0;
	
	private PartyLeader user;
	private PartyMember[] party;
	private Wagon wagon;

	private MainMenu mm;
	private PlayerConfiguration pc;
	private CreditScreen cs;
	
    /**
     * Starts the game session.
     */
	public void run()
	{
		runMainMenu();
		runPlayerConfiguration();
		runCreditScreen();
	}
	
    /**
     * Loads up Main Menu GUI and continues when "Start Game" button is pressed.
     */
	private void runMainMenu()
	{
		try
		{
			mm = new MainMenu();
			mm.setVisible(true);
			while (!mm.hasFinished())
				Thread.sleep(10);
			mm.setVisible(false);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	} //end runMainMenu
	
    /**
	 * Loads up Player Configuration GUI and continues when information is entered correctly.
     * Initializes PartyLeader, four PartyMember, and Wagon objects.
	 * Sets rations chosen, pace chosen and initial location for Wagon.
	 * Sets name and profession for PartyLeader
	 * Sets name for each PartyMember
     */
	private void runPlayerConfiguration()
	{
		try
		{
			pc = new PlayerConfiguration();
			pc.setVisible(true);
			while (!pc.hasFinished())
				Thread.sleep(10);
			
			String[] names = pc.getNames(); //retrieve array of names, 0 being PartyLeader and the rest PartyMember names
			wagon = new Wagon(pc.getPace(), START_LOCATION, pc.getRations());
			user = new PartyLeader(names[0], pc.getProfession());
			party = new PartyMember[PARTY_SIZE];
			for (int i = 0; i < PARTY_SIZE; i++)
			{
				party[i] = new PartyMember(names[i + 1]);
			}
			pc.setVisible(false);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	} //end runPlayerConfiguration
	
    /**
     * Loads Credit Screen GUI, must press "X" to close program.
     */
	private void runCreditScreen()
	{
		try {
			cs = new CreditScreen();
			cs.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	} //end runCreditScreen
	
	public static void main(String[] args)
	{
		Game game = new Game();
		game.run();
	}
}
